import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/login/controller.dart';
import 'package:flutter_jd/routes/routing_constants.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/route_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 登录
class Login extends GetView<LoginController> {
  @override
  Widget build(BuildContext context) {
    Get.put(LoginController());

    return Scaffold(
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            GestureDetector(
              onTap: () {
                Get.back();
              },
              child: Container(
                width: 45.w,
                height: 45.w,
                child: Kit.iconFont(0xe639, Color(0xFF666666), 22.sp),
              ),
            ),
            Expanded(
              child: Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Align(
                      child: Container(
                        width: 75.r,
                        height: 75.r,
                        margin: EdgeInsets.only(top: 80.h),
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: Color(0xFFEEEEEE),
                            width: 2.w,
                          ),
                          borderRadius: BorderRadius.circular(75.r),
                        ),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(75.r),
                          child: Image.asset(
                            'assets/images/common/avatar.png',
                            fit: BoxFit.cover,
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 10.h),
                      child: Text(
                        '181****0190',
                        style: TextStyle(
                          fontSize: 15.sp,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 50.h),
                      child: Ink(
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            begin: Alignment.topLeft,
                            end: Alignment.bottomRight,
                            colors: [
                              Color(0xFFFA2F19),
                              Color(0xFFFA722E),
                            ],
                          ),
                          borderRadius: BorderRadius.circular(30.r),
                        ),
                        child: InkWell(
                          borderRadius: BorderRadius.circular(30.r),
                          splashColor: Color(0xFFFA2F19),
                          onTap: () {
                            controller.login();
                          },
                          child: Container(
                            width: 300.w,
                            height: 45.h,
                            alignment: Alignment.center,
                            child: Text(
                              '本机号码一键登录',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 14.sp,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      alignment: Alignment.center,
                      margin: EdgeInsets.only(top: 12.h),
                      child: Text(
                        '其他方式登录',
                        style: TextStyle(
                          color: Color(0xFF666666),
                          fontSize: 13.sp,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Obx(
                        () => GestureDetector(
                          onTap: () {
                            controller.agree.value = !controller.agree.value;
                          },
                          child: Container(
                            margin: EdgeInsets.only(top: 2.h),
                            padding: EdgeInsets.all(2.r),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: controller.agree.value
                                  ? Colors.red
                                  : Colors.transparent,
                              border: Border.all(
                                color: controller.agree.value
                                    ? Colors.red
                                    : Color(0xFF999999),
                              ),
                              borderRadius: BorderRadius.circular(12.r),
                            ),
                            child: Kit.iconFont(
                              0xe736,
                              controller.agree.value
                                  ? Colors.white
                                  : Color(0xFF999999),
                              8.sp,
                            ),
                          ),
                        ),
                      ),
                      Container(
                        width: 290.w,
                        margin: EdgeInsets.only(left: 5.w),
                        child: Wrap(
                          alignment: WrapAlignment.start,
                          children: [
                            _buildText('使用手机号一键登录即代表您已同意'),
                            _buildLinkText('《隐私协议》', PrivacyRoute),
                            _buildText('和'),
                            _buildLinkText('《账号认证服务条款》', PrivacyRoute),
                            _buildText('并使用本手机号码登录'),
                          ],
                        ),
                      )
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 20.h),
                    child: Text(
                      'XX账号为您提供本地号码登录服务',
                      style:
                          TextStyle(color: Color(0xFF999999), fontSize: 12.sp),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  _buildText(String text) {
    return Text(
      text,
      style: TextStyle(color: Color(0xFF999999), fontSize: 12.sp),
    );
  }

  _buildLinkText(String text, String page) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(page);
      },
      child: Text(
        text,
        style: TextStyle(color: Color(0xFF4a90e2), fontSize: 12.sp),
      ),
    );
  }
}
